/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2025-02-08 10:56:06
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2025-02-08 11:16:14
 * @FilePath: /2024-4-20-pipe/yjl_test_pipe/process_pool/test.hpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma once

#include<iostream>

#include<ctime>
#include<cstdlib>
#include<sys/types.h>
#include<unistd.h>

#define TaskNum 3

typedef void (*task_t) (); // 函数指针类型


void print()
{
    std::cout<<"i am print task"<<std::endl;
}
void download()
{
    std::cout<<"i am download task"<<std::endl;
}
void flush()
{
    std::cout<<"i am flush task"<<std::endl;
}

task_t tasks[TaskNum];// 任务码表

// 加载 任务
void loadtask()
{
    // 随机派发
    srand(time(nullptr)^getpid());

    tasks[0]=print;
    tasks[1]=download;
    tasks[2]=flush;
}

// 执行 任务
void excute_task(int number)
{
    if(number<0||number>2) return ;
    tasks[number]();
}

// 选择 任务
int select_task()
{
    return rand() % TaskNum;
}